package com.furschina.struts2.portal;

import java.util.Collection;

import javax.validation.Valid;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts2.convention.annotation.InterceptorRef;
import org.apache.struts2.convention.annotation.InterceptorRefs;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.stereotype.Controller;

import cn.wooshai.core.struts2.PaginationAware;
import cn.wooshai.core.struts2.WooshaiAction;
import cn.wooshai.core.vo.PageModel;

import com.furschina.Constants;
import com.furschina.model.Navigation;
import com.furschina.service.NavigationService;
import com.furschina.struts2.BaseAction;

/**
 * 
 * @author zyc
 * 
 */
@Controller("portal/navigation")
@InterceptorRefs({ @InterceptorRef(Constants.DEFAULT_STACK_REF),
		@InterceptorRef(Constants.VALIDATOR_REF) })
@Result(name = WooshaiAction.SUCCESS, type = "redirect", location = "home.xhtml")
public class NavigationAction extends BaseAction implements PaginationAware {

	/**
	 * 
	 */
	private static final long serialVersionUID = -7466117221682245798L;

	/**
	 * 
	 */

	static Log LOG = LogFactory.getLog(NavigationAction.class);

	@Valid
	private Navigation model;

	private Long id;

	private Collection<Navigation> list;

	private PageModel pm = new PageModel();

	private NavigationService navigationService;

	/**
	 * @return the id
	 */
	public Long getId() {
		return id;
	}

	/**
	 * @param id
	 *            the id to set
	 */
	public void setId(Long id) {
		this.id = id;
	}

	/**
	 * @return the list
	 */
	public Collection<Navigation> getList() {
		return list;
	}

	/**
	 * @param list
	 *            the list to set
	 */
	public void setList(Collection<Navigation> list) {
		this.list = list;
	}

	/**
	 * @param model
	 *            the model to set
	 */
	public void setModel(Navigation model) {
		this.model = model;
	}

	public void setNavigationService(NavigationService navigationService) {
		this.navigationService = navigationService;
	}

	public Navigation getModel() {
		return this.model;
	}

	@Override
	public PageModel getPm() {
		return pm;
	}

	@Override
	public void setPage(int page) {
		this.pm.setPage(page);
	}

	public String index() {
		list = navigationService.queryAll(pm);
		return INDEX;
	}
	
	public String show() {
		this.model = this.navigationService.findByPrimaryKey(id);
		return SHOW;
	}
	
	public String create() {
		this.navigationService.create(model);
		return SUCCESS;
	}
	
	public String update(){
		this.navigationService.update(model);
		return SUCCESS;
	}
	
	public String include(){
		this.navigationService.queryAll(pm);
		return null;
	}
}
